Post

Replies

Boosts

Views

Activity

Reply to ForEach Breaks Data Binding
I was having a similar issue when trying to create NavigationLinks inside of a ForEach loop. The destination View had random data from the iterative object (lesson in my case).           	ForEach(viewModel.additionalLessons) { lesson in                     NavigationLink(                         destination: LessonView(viewModel: LessonViewModel(lesson: lesson,                         isSelected: $viewModel.lessonSelected)),                         isActive: $viewModel.lessonSelected,                         label: {                             LessonRow(lesson: lesson)                         })         	  } I found both embedding it into a VStack AND removing the "isActive" parameter on the NavigationLink allowed me to Bind the iterative object (lesson) into my destination view. Now I consistently get an appropriate detail view on the row I select.       LazyVStack(spacing:0) {           ForEach(viewModel.bookLessons) { lesson in                     NavigationLink(                         destination: LessonView(viewModel: 				 LessonViewModel(lesson: lesson, 														 isSelected: $viewModel.lessonSelected)),                         label: {                             LessonRow(lesson: lesson)                         })                } 		 }
Jan ’21